package com.zz.ecommerce.declareManage.importB2CDeclareTax.waybill;

import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.constants.TableConstants;
import com.zz.ecommerce.declareManage.importB2CDeclareDirect.waybill.CbecLogisticsDao;
import com.zz.ecommerce.pojo.CbecLogistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by fanshilei on 2016/3/28.
 * <p/>
 * 进口B2C申报服务（保税）--运单管理
 */
@Controller
@RequestMapping("/importB2CTax/waybill")
@Scope("prototype")
public class TaxWaybillController {

    @Autowired
    private CbecLogisticsDao cbecLogisticsDao;

    /**
     * 运单管理初始页
     *
     * @return
     */
    @RequestMapping(value = "init", method = {RequestMethod.GET})
    public String init() {
        return "declareManage/importB2CDeclareTax/waybill/waybill";
    }

    /**
     * 运单详情页
     *
     * @return
     */
    @RequestMapping(value = "waybillDetail/{logisticsNo}", method = {RequestMethod.GET})
    public String waybillDetail(@PathVariable("logisticsNo") String logisticsNo, ModelMap map) {
        map.addAttribute("logisticsNo", logisticsNo);
        return "declareManage/importB2CDeclareTax/waybill/waybill_detail";
    }

    /**
     * 运单列表页查询List
     *
     * @param cbecLogistics
     * @param request
     * @return
     */
    @RequestMapping("/queryCbecLogisticsList")
    @ResponseBody
    public GridResult queryDeclareList(CbecLogistics cbecLogistics, GridRequest request) {
        return new GridResult(cbecLogisticsDao.page(TableConstants.CBEC_LOGISTICS, cbecLogistics, request.getStart(), request.getEnd(), request.getSortOrder()), request, cbecLogisticsDao.count(TableConstants.CBEC_LOGISTICS, cbecLogistics));
    }

    /**
     * 根据运单编号获得运单信息
     *
     * @param cbecLogistics
     * @return
     */
    @RequestMapping("/getCbecLogistics")
    @ResponseBody
    public CbecLogistics getCbecLogistics(CbecLogistics cbecLogistics) {
        return cbecLogisticsDao.query(TableConstants.CBEC_LOGISTICS, cbecLogistics);
    }

}
